package com.mindbook.vip.gawxchatinfo.controller.home;

import cn.shuibo.annotation.Encrypt;
import com.mindbook.vip.gawxchatinfo.entity.home.FirstPageInfo;
import com.mindbook.vip.gawxchatinfo.service.home.FirstPageInfoService;
import com.mindbook.vip.gawxchatinfo.utils.crud.CrudUtils;
import com.mindbook.vip.gawxchatinfo.utils.result.DataResult;
import com.mindbook.vip.gawxchatinfo.utils.result.Result;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultEnum;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @NAME: wxb
 * @DATE: 2022/4/29
 * @Description 首页标题
 **/
@Api(tags = "首页标题")
@RestController
@RequestMapping("firstPage")
public class FirstPageInfoController {

    @Autowired private FirstPageInfoService firstPageInfoService;

    @PostMapping("/")
    @ApiOperation(value = "新增")
    public Result add(FirstPageInfo firstPageInfo){

        //数据库持久化
        Integer add = firstPageInfoService.add(firstPageInfo);

        //持久化是否成功
        CrudUtils.validateAddResult(add);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_ADD_SUCCESS.getMsg());
    }

    @PutMapping("/")
    @ApiOperation(value = "修改")
    public Result update(FirstPageInfo firstPageInfo){

        Integer put = firstPageInfoService.put(firstPageInfo);

        CrudUtils.validateAddResult(put);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_UPDATE_SUCCESS.getMsg());
    }


    @GetMapping("/list")
    @ApiOperation(value = "查询-列表：不携带子类")
    public Result getList(){
        List<FirstPageInfo> all = firstPageInfoService.findAll();
        return ResultUtils.genSuccessResult(all);
    }

    @GetMapping("/list/details/list")
    @ApiOperation(value = "查询-列表，携带子类")
    public Result getListWithChild(){
        List allWithChild = firstPageInfoService.findAllWithChild();
        return ResultUtils.genSuccessResult(allWithChild);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        Integer integer = firstPageInfoService.removeByPrimaryKey(id);

        CrudUtils.validateDeleteResult(integer);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_DELETE_SUCCESS.getMsg());
    }



}
